import { agentStatusMarkApi } from "@/api/waybillManagement/financeWaybill";
import FormHook from "@/hook/formHook";
import { message } from "ant-design-vue";
import { Ref } from "vue";
export default function OperationHook(state: {
  loading: Ref<boolean>;
  formState: FinanceWaybill.AgentStatusSign;
  formDataRef: Ref<any>;
  emit: any;
  passData: Ref<Array<CustomerServiceWaybill.ListRows>>;
}) {
  const { formState, formDataRef, emit, passData, loading } = state;
  const { resetFields } = FormHook({ formState });
  const onFinish = () => {
    const { agentStatus } = formState;
    const params: any = {
      idList: passData.value.map((t: any) => t.id),
      agentStatus
    };
    loading.value = true;
    agentStatusMarkApi(params)
      .then((res: any) => {
        const { code } = res;
        if (code === 200) {
          message.success("操作成功!");
          emit("submit");
        }
      })
      .finally(() => (loading.value = false));
  };

  const onFinishFailed = (errorInfo: any) => {
    console.log("Failed:", errorInfo);
  };
  const resetHandle = () => {
    resetFields();
    formDataRef.value.clearValidate();
    emit("update:visible", false);
  };
  return {
    onFinish,
    onFinishFailed,
    resetHandle,
    resetFields
  };
}
